<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- <script src="https://unpkg.com/vue@3/dist/vue.global.js"></script> -->
    <script src="../node_modules/vue/dist/vue.global.js"></script>
</head>

<body>
    <div id="app">
        <!-- 实现一个组件通信案例 -->
        <div>
            <input type="text" name="" id="" v-model="username">
            <input type="text" v-model="content">
            <button @click="publishFn">发表</button>
        </div>
        <ul>
            <li v-for="item in publishArr" :key="item.id">
                <h2>发表人: {{item.username}}</h2>
                <p>发表内容: {{item.content}}</p>
            </li>
        </ul>
    </div>
</body>

</html>
<script>
    // 将上述代码拆分成组件,实现组件化开发

    const { createApp } = Vue;
    const vm = createApp({
        data() {
            return {
                count: 0,
                username: '',
                content: '',
                publishArr: [
                    {
                        id: 1,
                        username: '张三',
                        content: '我喜欢狂飙'
                    },
                    {
                        id: 2,
                        username: '李四',
                        content: '我喜欢三体'
                    }
                ]
            }
        },
        methods: {
            publishFn() {
                this.publishArr.push({
                    id: this.publishArr[this.publishArr.length - 1].id + 1,
                    username: this.username,
                    content: this.content
                })
            }
        },




    });

    //挂载根实例到根节点
    vm.mount('#app')

</script>